﻿using DNFImagePacks2Manager.Models;
using System.Collections.Generic;
using System.IO;

namespace DNFImagePacks2Manager.Helpers
{
    public sealed class BKListHelper
    {
        public static List<BKItemSingle> GetSingleBKItems()
        {
            List<BKItemSingle> bkItems = [];
            string BKFolder = BKHelper.GetSingleFolder();

            if (string.IsNullOrEmpty(BKFolder) || !Directory.Exists(BKFolder))
            {
                return bkItems;
            }
            string[] files = Directory.GetFiles(BKFolder);

            foreach (string file in files)
            {
                BKItemSingle bkItem = new BKItemSingle(Path.GetFileName(file));

                bkItems.Add(bkItem);
            }
            return bkItems;
        }

        public static List<BKItemWhole> GetWholeBKItems()
        {
            List<BKItemWhole> bkItems = [];
            string BKFolder = BKHelper.GetWholeFolder();

            if (string.IsNullOrEmpty(BKFolder) || !Directory.Exists(BKFolder))
            {
                return bkItems;
            }
            string[] folders = Directory.GetDirectories(BKFolder, "*", SearchOption.TopDirectoryOnly);

            foreach (string folder in folders)
            {
                BKItemWhole bkItem = new BKItemWhole(Path.GetFileName(Path.GetFullPath(folder)));

                bkItems.Add(bkItem);
            }
            return bkItems;
        }

        public static List<BKItemCustom> GetCustomBKItems()
        {
            List<BKItemCustom> customItems = [];
            string BKFolder = BKHelper.GetCustomFolder();

            if (string.IsNullOrEmpty(BKFolder) || !Directory.Exists(BKFolder))
            {
                return customItems;
            }
            string[] files = Directory.GetFiles(BKFolder);

            foreach (string file in files)
            {
                BKItemCustom bkItem = new BKItemCustom(Path.GetFileName(file));

                customItems.Add(bkItem);
            }
            return customItems;
        }

        public static List<BKItemBase> GetAllBKItems()
        {
            List<BKItemBase> bkItems = [];
            bkItems.AddRange(GetWholeBKItems());
            bkItems.AddRange(GetCustomBKItems());
            bkItems.AddRange(GetSingleBKItems());
            return bkItems;
        }
    }
}
